<template>
<div class="PositionCorrelation">
    <el-table
    :data="list"
    v-loading="loading"
    style="width: 100%">
    <el-table-column
      label="申请时间"
      prop="applyTime">
    </el-table-column>
    <el-table-column
      label="招聘会名称"
      prop="jobFairName">
    </el-table-column>
    <el-table-column
      label="审核状态"
      prop="appliedStatus">
      <template slot-scope="scope">
          <div v-if="scope.row.appliedStatus == '0'"><el-tag type="warning">审核中</el-tag></div>
          <div v-if="scope.row.appliedStatus == '1'"><el-tag type="success">已通过</el-tag></div>
          <div v-if="scope.row.appliedStatus == '2'"><el-tag type="danger">审核未通过</el-tag></div>
      </template>
    </el-table-column>
    <el-table-column
      label="操作"
      align="center">
      <template slot-scope="scope">
          <el-popover
            placement="right"
            trigger="click">
            <el-button
            size="mini"
            @click="handleAddPosition(scope.$index, scope.row)">为此招聘会添加职位</el-button>
            <el-table :data="scope.row.jobList">
                <el-table-column property="posName" label="职位名称"></el-table-column>
                <el-table-column property="posNature" label="工作性质"></el-table-column>
                <el-table-column property="salary" label="薪资标准"></el-table-column>
                <el-table-column property="education" label="学历要求">
                    <template slot-scope="scope">
                      <div v-if="scope.row.education == '0'">小学</div>
                      <div v-if="scope.row.education == '1'">初中</div>
                      <div v-if="scope.row.education == '2'">高中</div>
                      <div v-if="scope.row.education == '3'">大专</div>
                      <div v-if="scope.row.education == '4'">本科</div>
                      <div v-if="scope.row.education == '5'">硕士</div>
                      <div v-if="scope.row.education == '6'">博士</div>
                    </template>
                </el-table-column>
                <el-table-column property="partment" label="工作部门"></el-table-column>
                <el-table-column
                fixed="right"
                label="操作"
                width="100">
                <template slot-scope="scope">
                    <el-button @click="handleExitPosition(scope.row)" type="text" size="small">编辑</el-button>
                    <el-button @click="handleRemovePosition(scope.row)" slot="reference" type="text" size="small">删除</el-button>
                </template>
                </el-table-column>
            </el-table>
            <el-button
            size="mini"
            slot="reference"
            type="text"
            @click="handleinlineinfo(scope.row)"
            >查看此招聘会发布职位</el-button>
            </el-popover>
       

      </template>
    </el-table-column>
  </el-table>
  <div style="height: 20px;"></div>   
  <div style="text-align: center;">
      <el-pagination
      @current-change="handleCurrentChange"
      :current-page.sync="page"
      :page-size="number"
      layout="prev, pager, next, jumper"
      :total="total">
    </el-pagination>
  </div>

  <el-dialog
    :visible.sync="dialogVisible">
    <UpdateFrom :list="positionOperationList" :model="positionOperationListModel"></UpdateFrom>
    <span slot="footer" class="dialog-footer">
        <el-button @click="handleClose">取 消</el-button>
        <el-button type="primary" @click="handleSubmit(shape)">确 定</el-button>
    </span>
    </el-dialog>

    <el-dialog
    width="30%"
    :visible.sync="dialogDelVisible">
    <span>确定删除此职位信息么？</span>
    <span slot="footer" class="dialog-footer">
        <el-button @click="dialogDelVisible = false">取 消</el-button>
        <el-button type="primary" @click="handleSureRemovePosition">确 定</el-button>
    </span>
    </el-dialog>

  
</div>
</template>

<script>
import UpdateFrom from '../components/UpdateFrom.vue'
import { verifyFrom } from '@/common/utils'
export default {
  methods: {
    handleClick(row) {
    console.log(row);
    },
    handleCurrentChange(page){
      this.page = page;
    },

    async handleAddPosition(){
      this.positionOperationListModel = {   
            "jobFairId": "",
            "jobFairName": "",
            "comId": "",
            "comName": "",
            "posName": "",
            "posNature": "",
            "posArea": "",
            "salary": "",
            "partment": "",
            "education": "",
            "experience": "",
            "gender": "",
            "age": "",
            "wantedNum": "",
            "jobDescribe": "",
            "linkman": "",
            "mobile": "",
            "email": "",
            "address": "",
            "level": "",
            "param1": [],
            "param2": '',
            "auditStatus": 1
        };
      this.dialogVisible = true;
    },

    handleClose(){
      this.dialogVisible = false;
    },

    handleinlineinfo(res){
      console.log(res)
      this.jobFairId = res.jobFairId;
      this.jobFairName = res.jobFairName;
    },

    async handleSureRemovePosition(){
      console.log(this.removePositionModel)
      let res = await this.$store.dispatch('handleSureRemovePosition', [this.removePositionModel.jobId]);
      console.log(res)
      if(res.code == 0){
          this.dialogDelVisible = false;
          this.init();
      }
    },

    handleRemovePosition(res){
      this.removePositionModel = res;
      this.dialogDelVisible = true;
    },

    handleExitPosition(res){
      this.shape = 'exit';
      this.positionOperationListModel = res;

      this.positionOperationListModel.param1 = this.positionOperationListModel.param1.split(',');
      this.dialogVisible = true;
    },

    async init(page=this.page){
      this.loading = true;
      let res = await this.$store.dispatch('getjobfairappliedlist', {
          comId: this.comId,
          pageSize: this.number,
          pageNumber: page,
          auditStatus: "1",
          display: "1"
        });
      console.log(res)
      setTimeout(()=>{
        this.loading = false;
      },500)

      if(res.code !== 0) return;
      this.total = res.page.total;
      this.list = res.page.rows;

      
    },

    async handleSubmit(shape){
      this.positionOperationListModel.jobFairId = this.jobFairId;
      this.positionOperationListModel.jobFairName = this.jobFairName;
      this.positionOperationListModel.comId = this.comId;
      this.positionOperationListModel.comName = this.comName;
      this.positionOperationListModel.param1 = this.positionOperationListModel.param1.toString();
      
      let ruleres = await new verifyFrom(this.positionOperationList,this.positionOperationListModel).initialMate();
      if(ruleres.length !== 0){
        console.log(ruleres)
        this.$message.error(ruleres[0]);
        return;
      }
      if(shape == 'add'){
        let res = await this.$store.dispatch('handleAddPosition', this.positionOperationListModel);
        console.log(res)
        if(res.code == 0){
            this.handleClose();
            this.init();
        }
      }else if(shape == 'exit'){
        let res = await this.$store.dispatch('handleExitPosition', this.positionOperationListModel);
        console.log(res)
        if(res.code == 0){
            this.handleClose();
            this.init();
        }
      }
    }
  },
  mounted(){
    this.init();

    this.positionOperationListModel.param1 = [];
  },
  data(){
      return {
        page: 1,
        number: 10,
        total: 0,
        list: [],
        positionList: [],
        positionPage: 1,
        positionNumber: 10,
        positionTotal: 0,
        comId: this.$store.state.home.globalUserInfo.company.comId,
        dialogVisible: false,
        shape:'add',
        jobFairId: "",
        jobFairName: "",
        visible: [],
        loading: false,
        dialogDelVisible: false,
        comName: this.$store.state.home.globalUserInfo.company.name,
        positionOperationList: [
            { title: '职位名称', model: 'posName', type: 'text', intertype:"text", rule:[
                'required',
            ]},
            { title: '职位性质', model: 'posNature', type: 'state', intertype:"text", rule:[
                'required',
            ],
              data: [
                  { label: '全职', value: '全职' },
                  { label: '兼职', value: '兼职' },
                  { label: '实习生', value: '实习生' },
              ]
            },
            { title: '工作区域', model: 'posArea', type: 'text', intertype:"text", rule:[
                'required',
            ] },
            { title: '薪资标准', model: 'salary', type: 'text', intertype:"text", rule:[
                'required',
            ] },
            { title: '工作部门', model: 'partment', type: 'text', intertype:"text", rule:[
                'required',
            ] },
            { title: '学历要求', model: 'education', type: 'state', intertype:"text",
              data: [
                  { label: '小学', value: '0' },
                  { label: '初中', value: '1' },
                  { label: '高中', value: '2' },
                  { label: '大专', value: '3' },
                  { label: '本科', value: '4' },
                  { label: '硕士', value: '5' },
                  { label: '博士', value: '6' },
              ], 
              rule:[
                'required',
              ]
             },
            { title: '工作经验(年)', model: 'experience', type: 'text', intertype:"number", rule:[
                'required',
            ] },
            { title: '性别', model: 'gender', type: 'state', intertype:"text",
              data: [
                  { label: '男', value: '男' },
                  { label: '女', value: '女' },
                  { label: '不限', value: '不限' },
               ], 
               rule:[
                'required',
                ]
            },
            { title: '年龄', model: 'age', type: 'text', intertype:"number", rule:[
                'required',
            ] },
            { title: '招聘人数', model: 'wantedNum', type: 'text', intertype:"number", rule:[
                'required',
            ] },
            { title: '联系人', model: 'linkman', type: 'text', intertype:"text", rule:[
                'required',
            ] },
            { title: '联系电话', model: 'mobile', type: 'text', intertype:"number", rule:[
                'required',
            ] },
            { title: '电子邮箱', model: 'email', type: 'text', intertype:"text", rule:[
                'required',
            ] },
            { title: '公司地址', model: 'address', type: 'text', intertype:"text", rule:[
                'required',
            ] },
            { title: '企业规模', model: 'level', type: 'text', intertype:"text", rule:[
                'required',
            ] },
            { title: '职位类别（例：开发）', model: 'param2', type: 'text', intertype:"text", rule:[
                'required',
            ] },
            { title: '职位亮点', model: 'param1', type: 'checkbox-group', intertype:"text",
              data: [
                  { label: '五险一金', value: '五险一金' },
                  { label: '年终分红', value: '年终分红' },
                  { label: '员工旅游', value: '员工旅游' },
                  { label: '带薪年假', value: '带薪年假' },
                  { label: '餐补', value: '餐补' },
                  { label: '房补', value: '房补' },
                  { label: '车补', value: '车补' },
                  { label: '话补', value: '话补' },
                  { label: '出差补助', value: '出差补助' },
              ], 
              rule:[
                'required',
              ]
            },
            { title: '岗位职责', model: 'jobDescribe', type: 'editor', intertype:"number", rule:[
                'required',
            ]},
        ],

        positionOperationListModel: {        //企业信息设置
            "jobFairId": "",
            "jobFairName": "",
            "comId": "",
            "comName": "",
            "posName": "",
            "posNature": "",
            "posArea": "",
            "salary": "",
            "partment": "",
            "education": "",
            "experience": "",
            "gender": "",
            "age": "",
            "wantedNum": "",
            "jobDescribe": "",
            "linkman": "",
            "mobile": "",
            "email": "",
            "address": "",
            "level": "",
            "param1": [],
            "param2": '',
            "auditStatus": 1
        },

        removePositionModel: {}
      }
  },
  components: {
    UpdateFrom,
  }
  
}
</script>

<style lang="less">
.PositionCorrelation {
  width: 100%;
  .demo-table-expand {
    font-size: 0;
  }
  .demo-table-expand label {
    width: 90px;
    color: #99a9bf;
  }
  .demo-table-expand .el-form-item {
    margin-right: 0;
    margin-bottom: 0;
    width: 50%;
  }
}
</style>
